package com.woniuxy.service.impl;

import com.woniuxy.entity.City;
import com.woniuxy.entity.Provincial;
import com.woniuxy.mapper.CityMapper;
import com.woniuxy.mapper.ProvincialMapper;
import com.woniuxy.service.ProvincialService;
import com.woniuxy.util.ResponseData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Array;
import java.util.ArrayList;
import java.util.List;

@Service
public class ProvincialServiceImpl implements ProvincialService {
    @Resource
    private ProvincialMapper provincialMapper;
    @Resource
    private CityMapper cityMapper;
    /**
     * 查询地址
     * 先查出所有省份
     * 再根据省份id查市
     * 组装数据
     * @return
     */
    @Override
    public ResponseData<?> queryProvincial() {
        List<Provincial> provincials = provincialMapper.queryProvincial();
        List<Provincial> provincialList = new ArrayList<>();
        for (Provincial provincial : provincials) {
            Integer id = provincial.getId();
//            String name = provincial.getName();
//            Provincial provincial1 = new Provincial();
//            provincial1.setId(id);
//            provincial1.setName(name);
            List<City> cities = cityMapper.queryCity(id);
            provincial.setCityList(cities);
            provincialList.add(provincial);
        }
        return new ResponseData<>().ok(provincialList);
    }
}
